package org.example.common.config;

import lombok.extern.slf4j.Slf4j;
import org.example.common.JsonResult;
import org.example.enums.BaseErrorEnums;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ControllerAdviceConf {

    @ExceptionHandler(Exception.class)
    public JsonResult exception(Exception exception){
        log.error("系统异常",exception);
        return JsonResult.error(BaseErrorEnums.SYS_ERROR.getMsg(),null,BaseErrorEnums.SYS_ERROR.getCode()+"");
    }

    @ExceptionHandler(BaseErrorException.class)
    public JsonResult baseErrorException(BaseErrorException baseErrorException){
        log.error("自定义异常",baseErrorException);
        return JsonResult.error(baseErrorException.getMsg(),null,baseErrorException.getCode()+"");
    }
}
